home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Practical Algorithms for Image Analysis
/
Practical Algorithms for Image Analysis.iso
/
CH_5.2
/
LINEFEAT
/
LINEFEAT.C
< prev
next >
Wrap
C/C++ Source or Header
|
1999-09-11
|
6KB
|
193 lines
/*
* linefeat.c
*
* Practical Algorithms for Image Analysis
*
* Copyright (c) 1997, 1998, 1999 MLMSoftwareGroup, LLC
*/
/* LINEFEAT: program decodes PCC and writes out line features
* usage: linefeat infile [-s] [-L]
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "pcc2.h" /* for PCC programs */
extern void print_sos_lic ();
unsigned char *fcCode; /* code storage */
long nByteCode; /* no. bytes in code storage */
long usage (short);
long input (int, char **, short *);
main (argc, argv)
int argc;
char *argv[];
{
long width, height; /* image size */
struct attributes *attr; /* level 1 attributes */
long nAttr; /* no. of line structures in attr. array */
short sumFlag; /* flag =1, write out only summary; or =0 */
long sumLength; /* sum of line lengths */
long sumPix; /* sum of number of pixels in lines */
long sumBoxX, sumBoxY; /* sum of bounding box x,y lengths */
long sumX, sumY; /* sum of x,y centroids of lines */
long i;
/* user input */
if (input (argc, argv, &sumFlag) < 0)
return (-1);
/* open input PCC file */
if (pccread (argv[1], &fcCode, &nByteCode, &width, &height) == -1)
exit (1);
printf ("image size: %dx%d, PCC length = %d\n", width, height, nByteCode);
/* construct tables of PCC decodes */
pccdecodes ();
/* construct TLC level 1 array of attributes */
tlc1attr (&attr, &nAttr);
/* summary information */
sumLength = sumPix = sumBoxX = sumBoxY = sumX = sumY = 0;
for (i = 0; i < nAttr; i++) {
sumLength += attr[i].length;
sumPix += attr[i].nPts;
sumBoxX += (attr[i].box.max.x - attr[i].box.min.x);
sumBoxY += (attr[i].box.max.y - attr[i].box.min.y);
sumX += attr[i].sumPt.x;
sumY += attr[i].sumPt.y;
}
printf ("Line Feature Summary:\n");
printf ("\tnumber of line features = %d\n", nAttr);
printf ("\taverage line length = %5.1f\n", (double) sumLength
/ ((double) nAttr * 10.0));
printf ("\taverage number of pixels per line = %5.1f\n",
(double) sumPix / (double) nAttr);
printf ("\taverage bounding box size = %5.1f x %5.1f [pixels]\n",
(double) sumBoxX / (double) nAttr,
(double) sumBoxY / (double) nAttr);
printf ("\taverage of line centroid locations = (%5.1f,%5.1f)\n",
(double) sumX / (double) sumPix, (double) sumY / (double) sumPix);
/* print line features for each line segment */
if (sumFlag)
return (1);
printf ("\nLine Features:\n");
for (i = 0; i < nAttr; i++) {
printf ("\n%d: ", i);
if (attr[i].type == 1)
printf ("Endline to Endline\n");
if (attr[i].type == 2)
printf ("Endline to Bifurcation\n");
if (attr[i].type == 3)
printf ("Endline to Cross\n");
if (attr[i].type == 4)
printf ("Bifurcation to Endline\n");
if (attr[i].type == 5)
printf ("Bifurcation to Bifurcation\n");
if (attr[i].type == 6)
printf ("Bifurcation to Cross\n");
if (attr[i].type == 7)
printf ("Cross to Endline\n");
if (attr[i].type == 8)
printf ("Cross to Bifurcation\n");
if (attr[i].type == 9)
printf ("Cross to Cross\n");
if (attr[i].type == 10)
printf ("Line Break to End\n");
if (attr[i].type == 11)
printf ("Line Break to Bifurcation\n");
if (attr[i].type == 12)
printf ("Line Break to Cross\n");
if (attr[i].type == 13)
printf ("Bifurcation Break to Endline\n");
if (attr[i].type == 14)
printf ("Bifurcation Break to Bifurcation\n");
if (attr[i].type == 15)
printf ("Bifurcation Break to Cross\n");
if (attr[i].type == 16)
printf ("Cross Break to Endline\n");
if (attr[i].type == 17)
printf ("Cross Break to Bifurcation\n");
if (attr[i].type == 16)
printf ("Cross Break to Cross\n");
printf ("\tlength = %5.1f, no. pixels = %d\n",
((double) attr[i].length / 10.0), attr[i].nPts);
printf ("\tstart and end coordinates: (%d,%d),(%d,%d)\n",
attr[i].pt1.x, attr[i].pt1.y, attr[i].pt2.x, attr[i].pt2.y);
printf ("\tstart and end line directions: %d, %d [deg]\n",
attr[i].dirn1, attr[i].dirn2);
printf ("\tbounding box: (%d,%d),(%d,%d)\n", attr[i].box.min.x,
attr[i].box.min.y, attr[i].box.max.x, attr[i].box.max.y);
printf ("\tcentroid: (%d,%d)\n", attr[i].sumPt.x / attr[i].nPts,
attr[i].sumPt.y / attr[i].nPts);
}
return (0);
}
/* USAGE: function gives instructions on usage of program
* usage: usage (flag)
* When flag is 1, the long message is given, 0 gives short.
*/
long
usage (flag)
short flag; /* flag =1 for long message; =0 for short message */
{
/* print short usage message or long */
printf ("USAGE: linefeat infile [-s] [-L]\n");
if (flag == 0)
return (-1);
printf ("\nlinefeat lists line features.\n\n");
printf ("ARGUMENTS:\n");
printf (" infile: input filename (PCC)\n\n");
printf ("OPTIONS:\n");
printf (" -s: only summary is printed.\n");
printf (" -L: print Software License for this module\n");
return (-1);
}
/* INPUT: function reads input parameters
* usage: input (argc, argv, sumFlag)
*/
#define USAGE_EXIT(VALUE) {usage (VALUE); return (-1);}
long
input (argc, argv, sumFlag)
int argc;
char *argv[];
short *sumFlag;
{
long n;
if (argc == 1)
USAGE_EXIT (1);
*sumFlag = 0;
for (n = 2; n < argc; n++) {
if (strcmp (argv[n], "-s") == 0)
*sumFlag = 1;
else if (strcmp (argv[n], "-L") == 0) {
print_sos_lic ();
exit (0);
}
else
USAGE_EXIT (0);
}
return (0);
}